﻿/* mvcForum
 * Copyright (C) 2010-2011 Steen F. Tøttrup
 * http://mvcforum.org/
 */

using System;

namespace mvcForum.Core {

	public class AttachmentLimitReachedException : AttachmentException {
		public readonly Int32 Usage;
		public readonly Int32 MaxUsage;

		public AttachmentLimitReachedException(Int32 usage, Int32 maxUsage)
			: base(String.Format("You're allowed to store {0} bytes of data, you have {1} bytes.", usage, maxUsage)) {

			this.Usage = usage;
			this.MaxUsage = maxUsage;
		}
	}

	public class AttachmentSizeException : AttachmentException {
		public readonly Int32 Size;
		public readonly Int32 MaxSize;

		public AttachmentSizeException(Int32 size, Int32 maxSize)
			: base(String.Format("The attachment is {0} bytes, the max allowed file size is {1}.", size, maxSize)) {

			this.Size = size;
			this.MaxSize = maxSize;
		}
	}

	public class InvalidExtensionException : AttachmentException {
		public readonly String Extension;

		public InvalidExtensionException(String extension)
			: base(String.Format("The extension {0} is not allowed.", extension)) {

			this.Extension = extension;
		}
	}

	public abstract class AttachmentException : ApplicationException {
		public AttachmentException(String message) : base(message) { }
	}

	public class NoAccessException : ApplicationException {
		public readonly Forum Forum;
		public readonly AccessFlag AccessFlag;

		public NoAccessException(Forum forum, AccessFlag flag)
			: base(String.Format("The user does not have the required access ({1}) to forum '{0}'.", forum.Name, flag)) {

			this.Forum = forum;
			this.AccessFlag = flag;
		}
	}

	/// <summary>
	/// A common base class for all new user exceptions.
	/// </summary>
	public abstract class NewUserException : ApplicationException {
		public NewUserException(string message) : base(message) { }
	}

	/// <summary>
	/// Exception used when an user is being created but an user with the same e-mail address already exists.
	/// </summary>
	public class DuplicateEmailAddressException : NewUserException {
		private readonly string EmailAddress;

		public DuplicateEmailAddressException(string email)
			: base(String.Format("The e-mail address {0} is already in use!", email)) {

			this.EmailAddress = email;
		}
	}

	/// <summary>
	/// Exception used when an user is being created but an user with the same name already exists.
	/// </summary>
	public class DuplicateNameException : NewUserException {
		private readonly string Name;

		public DuplicateNameException(string name)
			: base(String.Format("The name {0} is already in use!", name)) {

			this.Name = name;
		}
	}

	public abstract class LogOnException : ApplicationException {
		public LogOnException(string message) : base(message) { }
	}

	public class UserNotActiveException : LogOnException {
		public readonly ForumUser User;

		public UserNotActiveException(ForumUser user)
			: base(String.Format("The user {0} is not active.", user.Name)) {

			this.User = user;
		}
	}

	public class UserDeletedException : LogOnException {
		public readonly ForumUser User;

		public UserDeletedException(ForumUser user)
			: base(String.Format("The user {0} was deleted.", user.Name)) {

			this.User = user;
		}
	}
}